package itsecurity.collision;

import iaik.security.provider.IAIK;
import itsecurity.cert.MDBProvider;
import itsecurity.hash.roque.DaviesMeyerDESRoque;

import java.security.Security;
import java.util.StringTokenizer;

public class FindBirthdayBits {
	
	/**
	 * Give two byte arrays as string as parameters!
	 * The syntax for this string is: 'xx xx xx' , i.e.
	 * between every hex value there is a whitespace.
	 * 
	 * Length of these byte arrays has to be same and dividable by 7
	 * so that birthday-bit injecting is possible.
	 * 
	 * @param args
	 */
	public static void main (String[] args) {
	  
		try {
	    Security.insertProviderAt(new IAIK(), 2);
	    Security.insertProviderAt(new MDBProvider(), 3);
	  } catch( Throwable e ) {
	    //
	  }
	  
		StringTokenizer st = new StringTokenizer(args[1]," ",false);
	  String str1="";
	  while (st.hasMoreElements()) str1 += st.nextElement();

	  st = new StringTokenizer(args[2]," ",false);
	  String str2="";
	  while (st.hasMoreElements()) str2 += st.nextElement();
	  
	  byte[] data1 = iaik.utils.Util.toByteArray(str1);
	  byte[] data2 = iaik.utils.Util.toByteArray(str2);
	  
	  if (data1.length!=data2.length || data1.length%7!=0) {
	  	System.err.println("Arrays not equal length or not dididable by 7!");
	  	return;
	  }
	  
	  DaviesMeyerDESRoque des = new DaviesMeyerDESRoque();
	  try {
			des.doHash(data1, data2);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
